import path from 'path'
import { glob } from 'glob'
const getEntries = function () {
  let rootPath = './src';
  //查找所有入口文件 如果不限制文件后缀名，要加上.*否则连目录也会被当做文件
  let entryFiles = glob.sync('./src/*.*');
  let map = {};
  entryFiles.forEach(filePath => {
    // var fileName = filePath.substring(filePath.lastIndexOf('\/') + 1, filePath.lastIndexOf('.'));
    let fileName = filePath.replace('./src', '.');
    map[fileName] = filePath;
  });
  console.log(map);
  return map;
}
module.exports = {
  // entry: './src/t1.js',
  // output: {
  //   path: __dirname,
  //   filename: 'bundle.js'
  // },
  entry: getEntries(),
  output: {
    path: path.join(__dirname, 'dist'),
    filename: '[name]' //即为fileName，可识别路径
  },
  module: {
    //加载器配置
    loaders: [
      {test: /\.jsx?$/, loader: 'babel', exclude: /node_modules/,
        query: {
          presets: ['es2015','react']
        }
      },
      {test: /\.js$/, loader: 'babel-loader', exclude: /node_modules/}
    ]
  }
};
